<template>
  <el-card>
    <!-- 头部 -->
    <div slot="header" class="header">
      <div class="header-title">销售额类别占比</div>
      <!-- v-model="radio1" -->
      <el-radio-group v-model="value">
        <el-radio-button label="全部渠道"></el-radio-button>
        <el-radio-button label="线上"></el-radio-button>
        <el-radio-button label="门店"></el-radio-button>
      </el-radio-group>
    </div>
    <!-- 图表 -->
    <div>
      <div ref="charts" class="charts"></div>
    </div>
  </el-card>
</template>

<script>
import * as echarts from "echarts";
export default {
  data() {
    return {
      value: "全部渠道",
    };
  },
  mounted() {
    let myCharts = echarts.init(this.$refs.charts);
    myCharts.setOption({
      // 利用title的定位 将titl巧妙的放入饼图中间
      title: {
        // 主标题 图表name
        text: "视频",
        //   次标题 图标value
        subtext: 1048,
        top: "center",
        left: "center",
      },
      tooltip: {
        trigger: "item",
      },
      series: [
        {
          name: "Access From",
          type: "pie",
          radius: ["40%", "70%"],
          avoidLabelOverlap: false,
          itemStyle: {
            borderRadius: 10,
            borderColor: "#fff",
            borderWidth: 2,
          },
          label: {
            show: true,
            // 将标题放在饼图外面
            position: "outside",
          },

          labelLine: {
            // 是否需要标题线条
            show: true,
          },
          data: [
            { value: 1048, name: "视频" },
            { value: 735, name: "Direct" },
            { value: 580, name: "Email" },
            { value: 484, name: "Union Ads" },
            { value: 300, name: "Video Ads" },
          ],
        },
      ],
    });
    //     echarts封装的鼠标移动事件 可以拿到鼠标移动经过的图表的 value name
    myCharts.on("mouseover", (params) => {
      const { value, name } = params.data;
      myCharts.setOption({
        title: {
          text: name,
          subtext: value,
        },
      });
    });
  },
};
</script>

<style scoped >
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #ccc;
}
.header-title {
  font-size: 14px;
  color: #ccc;
}
.charts {
  width: 100%;
  height: 228px;
}
</style>